/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session.stateful;

import entity.CustomerEntity;
import java.util.List;
import javax.ejb.Stateful;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Dao Thai Duy
 */
@Stateful
@LocalBean
public class CustomerSessionBean {

    @PersistenceContext
    private EntityManager entityManager;
    private StakeholderSessionBean stakeholderSessionBean;
    
    public List<CustomerEntity> getAllCustomers(){
        Query query = getEntityManager().createQuery("SELECT c FROM CustomerEntity c");
        return query.getResultList();
    }
    public List<CustomerEntity> getCustomerByEmail(String email){
        Query query= entityManager.createQuery("SELECT c FROM CustomerEntity c WHERE c.email= :email");
        query.setParameter("email", email);
        return query.getResultList();
    }
    public List<String> getAllEmails(){
        Query query = getEntityManager().createQuery("SELECT c.email FROM CustomerEntity c");
        return query.getResultList();
    }
    public EntityManager getEntityManager() {
        return entityManager;
    }

    public void setEntityManager(EntityManager entityManager) {
        this.entityManager = entityManager;
    }

    public StakeholderSessionBean getStakeholderSessionBean() {
        return stakeholderSessionBean;
    }

    public void setStakeholderSessionBean(StakeholderSessionBean stakeholderSessionBean) {
        this.stakeholderSessionBean = stakeholderSessionBean;
    }
    public CustomerEntity getCustomerById(Long id){
        return entityManager.find(CustomerEntity.class, id);
    }
}
